<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class GoodUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->request->get('id');
        return [
            'cate_id' => ['required', 'integer'],
            'name' => ['required', Rule::unique('goods')->ignore($id)],
            'price' => ['required', 'numeric'],
            'price_agent_one' => ['required', 'numeric'],
            'price_agent_two' => ['required', 'numeric'],
            'good_img' => ['required']
        ];
    }
    public function messages()
    {
        return [
            'cate_id.required' => '请选择商品所属分类',
            'cate_id.integer' => '分类选择异常',
            'name.required' => '商品名称必填',
            'name.unique' => '商品名称已存在',
            'price.required' => '市场价必填',
            'price.numeric' => '市场价必须为数字',
            'price_agent_one.required' => '一级代理价必填',
            'price_agent_one.numeric' => '一级代理价必须为数字',
            'price_agent_two.required' => '二级代理价必填',
            'price_agent_two.numeric' => '二级代理价必须为数字',
            'good_img.required' => '商品图片不能留空'
        ];
    }
}
